<?php
/**
 * JoiGallery - image gallery component for Joostina
 *
 * Frontend View handler
 *
 * @version 1.0 alpha 3
 * @package JoiGallery
 * @filename joigallery.html.php
 * @author JoostinaTeam
 * @copyright (C) 2008-2009 Joostina Team
 * @license see license.txt
 *
 **/

// запрет прямого доступа
defined('_VALID_MOS') or die();

class HTML_joigallery {
	
	function showPhoto($row,  $params){
		global $my, $_MAMBOTS; 		
 		$_MAMBOTS->loadBotGroup('content');
 		
		$mainframe = &mosMainFrame::getInstance();
		$database = &database::getInstance();
		
		joiGalleryHelper::fixPathway($row->cid, $row);
		
		$mainframe->setPageTitle(sprintf(_C_JOIGALLERY_VIEW_PHOTO, $row->name));
		
        $prev_link = $next_link = '';
        if($row->prev){
            $prev_link_1 = isset($row->prev[0]) ?  sefRelToAbs('index.php?option=com_foto&amp;task=view&amp;id='.$row->prev[0]->id) : '#';

        }
        if($row->next){
            $next_link_1 = isset($foto->prev[0]) ?  sefRelToAbs('index.php?option=com_foto&amp;task=view&amp;id='.$row->next[0]->id) : '#';
        }
        
        //Плагины
        $plugins = new joiGalleryPlugins($mainframe);
        $plugins->init('foto-view', $row, $params);
        
        //Дополнительные поля
        $extra_fields = new joiExtraFields($mainframe, 'com_joivideo');
        
     	//Комментарии (JComments))	
        if ($params->get( 'comments' )){
			//$comments = $_MAMBOTS->call('onPrepareJoiComments');
            $comments = $mainframe->getCfg('absolute_path') . '/components/com_jcomments/jcomments.php';
            
            if (file_exists($comments)) {
                    require_once($comments);                    
            }
            else{
                $params->set( 'comments',0);    
            }
		}
        		
		$template = new joiTemplates('com_joivideo');
		if($template->get_template('item', $params->template_dir, $params->template_photo)){
			include_once($template->template_file);	
		}    
  	}  

	function editPhoto($photo, $params) {
		global $my;
		$mainframe = &mosMainFrame::getInstance();
        
        //Дополнительные поля
        $extra_fields = new joiExtraFields($mainframe, 'com_joivideo');
	  
		$mainframe->set('allow_wysiwyg', 1);
	  	$wwig_params = array('m_buttons' => 0);
		
		$template = new joiTemplates('com_joivideo');
		if($template->get_template('edit-photo', $params->template_dir, $params->template_edit_photo)){
			include_once($template->template_file);	
		}
			 
	}	

	function newPhoto($params){
	  	global $my;
	  	$mainframe = &mosMainFrame::getInstance();
	  	$database = &database::getInstance();
        
        //Дополнительные поля
        $extra_fields = new joiExtraFields($mainframe, 'com_joivideo');
        		  	  
	  	$mainframe->setPageTitle(_C_JOIGALLERY_UPLOAD_PHOTOS);
	  	
	  	$mainframe->set('allow_wysiwyg', 1);
	  	$wwig_params = array('m_buttons' => 0);
	  	
	  	mosCommonHTML::loadOverlib();

	    $categories = joiGalleryCategory::getCategorieTree();
		
		$template = new joiTemplates('com_joivideo');
		if($template->get_template('upload-photo', $params->template_dir, $params->template_add_photo)){
			include_once($template->template_file);	
		}
	}  

  	function showCategory($cat, $photos,  $params){
  		
		global  $my, $_MAMBOTS; 
		
		$mainframe = &mosMainFrame::getInstance();
		$database = &database::getInstance();
		
		$mainframe->addLib('text');
		
		$subcats = $cat->subcats;
		$photos = $photos->content;
		$total = $cat->total; 
		
		joiGalleryHelper::fixPathway($cat->id); 
		
		require_once ($mainframe->getCfg('absolute_path') . '/includes/pageNavigation.php');
    	$pageNav = new mosPageNav($total, $params->_limitstart, $params->_limit);	
		
		if(!$params->_cid && !$cat->name){
			$page_type = 'mainpage'; 
			$mainframe->setPageTitle(_C_JOIGALLERY_SHOWCATEGORIES);
		} 
		else{
			$page_type = 'category';
			$mainframe->setPageTitle(sprintf(_C_JOIGALLERY_SHOWCATEGORY, $cat->name));	
		}
		
        //Рейтинг
		if($params->get('image_rate_cat_view', 1)){
			$_MAMBOTS->loadBotGroup('content');
			//$rating = $_MAMBOTS->call('onPrepareRating');  			
		}
        
     	//Комментарии (JComments))	
        if ($params->get( 'comments_cat_view' )){
			//$comments = $_MAMBOTS->call('onPrepareJoiComments');
            $comments = $mainframe->getCfg('absolute_path') . '/components/com_jcomments/jcomments.php';
            
            if (file_exists($comments)) {
                    require_once($comments);                    
            }
            else{
                $params->set( 'comments_cat_view',0);    
            }
		}

		$template = new joiTemplates('com_joivideo');
		if($template->get_template($page_type, $params->template_dir, $params->template_cat)){
			include_once($template->template_file);	
		}   

  	}  

	function editCategory($cat, $params) {
		global $my;
		$mainframe = &mosMainFrame::getInstance();		
			
		$mainframe->set('allow_wysiwyg', 1);
	  	$wwig_params = array('m_buttons' => 0);

		$template = new joiTemplates('com_joivideo');
		if($template->get_template('edit-category', $params->template_dir, $params->template_edit_cat)){
			include_once($template->template_file);	
		}
	}

	function navPrevNext($row,  $params){
    	$mainframe = &mosMainFrame::getInstance();
    	
    	$link = 'index.php?option=' . $params->_option . '&amp;act=photos&amp;cid=';    
    	$link = sefRelToAbs( $link . $row->id . '&amp;Itemid=' . $params->_Itemid );
		?>

		<a class="photo_nav" href="<?php echo $link; ?>" title="<?php echo $row->description;?>">
     		<img src="<?php echo $mainframe->getCfg('live_site') . $params->thumbnail_path . '/' . $row->path; ?>" border="0" alt="<?php echo $row->description; ?>" title="<?php echo $row->description; ?>" />
       </a>	
		<?php
	
  	}  

  	function buttonAddCat($row, $params){
    	global $my;
    
    	$link = sefRelToAbs( 'index.php?option=' . $params->_option . '&amp;act=' . $params->_act .'&amp;task=new&amp;cid=' . $row->id . '&amp;Itemid=' . $params->_Itemid );
    	if($params->_access->allow_me('add_cat', $my->_gid)){ ?> 
			<span class="button"><a class="button" href="<?php echo $link; ?>"><?php echo _C_JOIGALLERY_ADD_CATEGORY2;?></a></span>
    	<?php }

  	}  

  	function buttonUploadPhoto($row, $params){
    	global $my;
    
 		$link = sefRelToAbs( 'index.php?option=' . $params->_option . '&amp;act=photos&amp;task=new&amp;cid=' . $row->id . '&amp;Itemid=' . $params->_Itemid );    
  	
	  	if($params->_access->allow_me('add_photo_single', $my->_gid) || $params->_access->allow_me('add_photo_archive', $my->_gid) ){ ?> 
			<span class="button"><a class="button" href="<?php echo $link; ?>"><?php echo _C_JOIGALLERY_UPLOAD;?></a></span> 
    	<?php }
  	} 

  	function buttonEditPhoto($row, $params){
    	global $my;    
     
 		$link = sefRelToAbs( 'index.php?option=' . $params->_option . '&amp;act=' . $params->_act .'&amp;task=edit&amp;cid=' . $row->id . '&amp;Itemid=' . $params->_Itemid ); 	 
		
		$button = _C_JOIGALLERY_EDIT_PHOTO;	
	  
	  	if(
		  	$params->_access->allow_me('edit_photo', $my->_gid)
		  	or
		  	($params->_access->allow_me('edit_own_photo', $my->_gid) && $my->id == $row->user_id)
		  ){ ?> 
			<span class="button"><a class="button" href="<?php echo $link; ?>"><?php echo $button ;?></a></span> 
    	<?php }    

  	}  	
  	
  	function buttonEditCat($row, $params){
    	global $my;    
     
 		$link = sefRelToAbs( 'index.php?option=' . $params->_option . '&amp;act=' . $params->_act .'&amp;task=edit&amp;cid=' . $row->id . '&amp;Itemid=' . $params->_Itemid );  
	 
		$button = _C_JOIGALLERY_EDIT_CATEGORY;
	
	  	if($params->_access->allow_me('edit_cat', $my->_gid)){ ?> 
			<span class="button"><a class="button" href="<?php echo $link; ?>"><?php echo $button ;?></a></span> 
    	<?php }    

  	}  

  	function buttonDeletePhoto($row, $params){
    	global $my;
	
		$link = sefRelToAbs( 'index.php?option=' . $params->_option . '&amp;act=' . $params->_act .'&amp;task=remove&amp;cid=' . $row->id . '&amp;Itemid=' . $params->_Itemid );
	

		$button = _C_JOIGALLERY_DELETE_PHOTO;
		$confirm = 	_C_JOIGALLERY_DELETE_CONFIRM_PHOTO;

		if(
		  	($params->_access->allow_me('del_photo', $my->_gid) && $my->id != $row->user_id)
		  	or
		  	($params->_access->allow_me('del_own_photo', $my->_gid) && $my->id == $row->user_id)
		  ){  ?>
    		<span class="button">
				<a class="button" href="javascript:void(0);" onclick="if(confirm('<?php echo $confirm;?>')){document.location.href='<?php echo $link;?>'}">
					<?php echo $button;?>
				</a>    	
    		</span>
    	<?php }
  	}
  	
  	function buttonDeleteCat($row, $params){
    	global $my;
	
		$link = sefRelToAbs( 'index.php?option=' . $params->_option . '&amp;act=' . $params->_act .'&amp;task=remove&amp;cid=' . $row->id . '&amp;Itemid=' . $params->_Itemid );
		
		$button = _C_JOIGALLERY_DELETE_CAT;
		$confirm = 	_C_JOIGALLERY_DELETE_CONFIRM_CATEGORY;		
		
    	if($params->_access->allow_me('del_cat', $my->_gid)){  ?>
    		<span class="button">
				<a  class="button" href="javascript:void(0);" onclick="if(confirm('<?php echo $confirm;?>')){document.location.href='<?php echo $link;?>'}">
					<?php echo $button;?>
				</a>    	
    		</span>
    	<?php }
  	}

}